﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MapInfo_DepartmentsList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //this.DptDepartment.SelectedIndexChanged += new EventHandler(DptDepartment_SelectedIndexChanged);

        if (!IsPostBack)
            Bind();

    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        this.GvwList.PageIndex = PageIndex;
        Bind2();
    }
    private void Bind()
    {
        this.DptDepartment.DataSource = Yipusoft.Account.BLL.Department.GetList(" Right(DepartmentID,2)='00'");
        this.DptDepartment.DataTextField = "FullName";
        this.DptDepartment.DataValueField = "DepartmentID";
        this.DptDepartment.DataBind();
        DptDepartment.Items.Insert(0, new ListItem("请选择单位", "00"));
    }
    protected void BtnSearch_Click(object sender, EventArgs e)
    {
        Bind2();
    }
    private void Bind2()
    {
        string strSql = string.Empty;
        if (txtName.Text.Trim() != "")
            strSql = " DepartmentName Like'%" + txtName.Text.Trim() + "%'";

        if (DptDepartment.SelectedValue.Equals("00"))
        {            
                goto thisline;            
        }

        
       

        if (DptDepartment.SelectedValue.Equals("1300000"))
        {
            if (strSql == string.Empty)
            {
                strSql = " 1=1 Order By DepartmentID";
                goto thisline;
            }
            else
            {
                strSql += " Order By DepartmentID";
                goto thisline;
            }
        }
        if (strSql != string.Empty)
        {
            if (!DptDepartment.SelectedValue.Equals("00"))
            {

                strSql += " And Left(DepartmentID,4) = '" + DptDepartment.SelectedValue.Substring(0,4) + "'";
            }
        }
        else
        {
            if (!DptDepartment.SelectedValue.Equals("00"))
            {
                strSql = "  Left(DepartmentID,4) = '" + DptDepartment.SelectedValue.Substring(0, 4) + "'";
            }
        }

        thisline:
        List<Yipusoft.Listener.Model.Departments> list = Yipusoft.Listener.BLL.Department.GetList(strSql);
        if (list != null)
        {
            this.GvwList.DataSource = list;
            this.ListPageContral1.ItemCount = list.Count;
            this.GvwList.DataBind();
        }
        
    }

    public string GetDepartmentType(object objID)
    {
        return "";

    }
    public string GetStationLevel(object objID)
    {
        if (objID == null)
            return "";
        Yipusoft.Common.Model.CodeItemInfo info = Yipusoft.Common.BLL.CodeItem.GetCodeItem(objID.ToString(), "XFZDJ");
        return info != null ? info.ItemName : "";
    }
    public string GetStationType(object objID)
    {
        if (objID == null)
            return "";
        Yipusoft.Common.Model.CodeItemInfo info = Yipusoft.Common.BLL.CodeItem.GetCodeItem(objID.ToString(), "XFZLB");
        return info != null ? info.ItemName : "";
        
    }
    protected void GvwList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = Convert.ToString(GvwList.PageSize * ListPageContral1.CurrentPageIndex + (e.Row.RowIndex + 1));
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
}
